﻿using AutoMapper;
using MediatR;
using NPOI.SS.Formula.Functions;
using PersonnelManagement.Application.Command.ClientCommand;
using PersonnelManagement.Domain.PersonnelDomain;
using PersonnelManagement.Infrstructre.Interface;

namespace PersonnelManagement.Application.CommandHandler.ClientCommandHandlers
{
    public class ClientBlikCommandHandlers : IRequestHandler<ClientBlikCommand, List<Client>>
    {
        IClientRepository mRep;
        IMapper mapper;
        public ClientBlikCommandHandlers(IClientRepository rep, IMapper mapper)
        {
            mRep = rep;
            this.mapper = mapper;
        }


        public async Task<List<Client>> Handle(ClientBlikCommand request, CancellationToken cancellationToken)
        {
            //var list = (await mRep.Getall()).Where(x => x.ClientId == request.Id).ToList();
            //return list;
            var list = (await mRep.Getall()).Where(x => x.ClientId == request.Id).ToList();
            return mapper.Map<List<Client>>(list);

        }
    }
}
